package com.zzz.robot201.mvp.ui.adapter;

import android.app.Activity;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zzz.robot201.R;
import com.zzz.robot201.mvp.model.api.bean.EquipmentBean;
import com.zzz.robot201.mvp.model.api.bean.MsgBean;


public class EquipmentAdapter extends BaseQuickAdapter<EquipmentBean.DataBean, BaseViewHolder> {

    public EquipmentAdapter() {
        super(R.layout.item_equipment);
    }

    @Override
    protected void convert(BaseViewHolder helper, EquipmentBean.DataBean item) {
        ViewGroup.LayoutParams layoutParams = helper.itemView.getLayoutParams();
        layoutParams.width = (getScreenWidth((Activity) mContext) / 3);
        helper.itemView.setLayoutParams(layoutParams);

        int position = helper.getLayoutPosition();


        if (!item.isSelect()){
            helper.setBackgroundRes(R.id.rl_equipment,R.drawable.ic_choice_box_mr);
        }else {
            helper.setBackgroundRes(R.id.rl_equipment,R.drawable.ic_choice_box);
        }
//        if (position==0){
//            helper.setBackgroundRes(R.id.rl_equipment,R.drawable.ic_choice_box);
//        }else {
//            helper.setBackgroundRes(R.id.rl_equipment,R.drawable.ic_choice_box_mr);
//        }
        helper.setText(R.id.tv_num, "编号:"+item.getDeviceCode());
        helper.setText(R.id.tv_ip, "IP:"+item.getDeviceIp());
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null)
                    onItemClickListener.onItemClick(position,helper.itemView);
                }
        });
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
    public interface OnItemClickListener {
        void onItemClick(int position, View view);
    }

    /**
     * 返回屏幕的宽度
     */
    public static int getScreenWidth(Activity activity) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
        return displayMetrics.widthPixels;
    }
}
